package com.huan.study.mybatis.handler;

import com.huan.study.mybatis.util.AESUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author YanXxx
 * @date 2022-11-03 18:01
 */
@Slf4j
@Component("aesEncryptImpl")
public class AESEncryptImpl implements EncryptHandler {

    @Value("${aes.key}")
    private String key;

    /**
     *
     * @param encryptValue 加密值
     * @return 加密后的值
     */
    @Override
    public String encryptMethod(String encryptValue){
        log.info("AES加密");
        if (!encryptValue.startsWith(AESUtil.KEY_SENSITIVE)) {
            String encrypted;
            encrypted = AESUtil.encrypt(encryptValue, key);
            encrypted = AESUtil.KEY_SENSITIVE + encrypted;
            return encrypted;
        }
        return encryptValue;
    }
}
